Repository navigation
Reimplement UpdateSlinger from gynt's units branch (100%, with names for unit state 123 and entity type 35) - #544
Merged
Conversation
UnitState gets US_UNKNOWN_123 = 123 and EntityType gets ET_UNKNOWN_35 = 35, one line each, named as the enums' other values without a known meaning are (US_UNKNOWN_120, US_UNKNOWN_121, ET_UNKNOWN_8, ET_UNKNOWN_30). Both are numbers the original has in UpdateSlinger 0x00572E80, which the next commit adds: - 123 is the highest case of its switch on the state (`cmp eax, 0x7b` at 0x00572EF4), the state it stores behind moveToFreeTileNearby when that call left the unit in US_MOVE_TO_DESTINATION (`add ecx, 0x7b` at 0x005732D3: 123 there, 4 for US_RELOAD_WEAPONUnk otherwise), and the value Unit::field_0x2c4 is tested for in front of that call (0x0057329D). field_0x2c4 is the short behind state and cachedState, and the block it guards stores state 123, so the field holds a state number and the test reads with the same name. - 35 is the entity type of the stone the slinger throws (`push 0x23` at 0x00573C8B, shootProjectile's second argument). ET_SLINGER is 33; 35 has no name yet. Four files on main write `(UnitState)123` for the same case label and the same store (UpdateArabianArcher, UpdateCrossbowman, UpdateCrusaderArcher, UpdateFireThrower). This commit leaves them as they are. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Units::UpdateSlinger at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 30448d6 at 28.29%, a43cf47 and e61e5a5 at 31.60%, 6565c1b, and the style commit 974c32f), through the forms on our development branches (96.5% there with OPENSHC_FUNCTION_VISIBILITY_UNITS on). What the match needed, against that text: - Where the sling is loaded and the target is a building, half the building's size is written in both sums (`.x + widthOrHeight / 2`, `.y + widthOrHeight / 2`) in place of a local for it. The original divides once (0x0057376D: cdq; sub eax, edx; sar edx, 1) and moves the quotient out of eax (0x00573770), so the target's y is in eax on this arm as on the arm for a unit (0x00573732), and edx is free for the zero that the test behind the join compares with and the state store uses (xor edx, edx at 0x0057377F, cmp ecx, edx at 0x00573781, the store at 0x005737B6, an exit that five jumps of another state share). With the local the quotient stays in eax, the y takes edx, the test is a `test ecx, ecx` and the store an immediate with an exit of its own. quick_diff with hasUnitReachedDestination in the unit: 0.9814 -> 0.9955 (1346 -> 1340 instructions, the original's count), and what is left is the same bytes written two ways (0xffff and -1, 0xfffe and -2). Number casts to UnitState are the enum's names. State 123 is US_UNKNOWN_123 in the case label, in the store behind moveToFreeTileNearby and in the test of field_0x2c4, the short behind state and cachedState, which holds a state too (0x00572EF4, 0x005732D3, 0x0057329D); the projectile is ET_UNKNOWN_35 (push 0x23 at 0x00573C8B). Both names come with the header commit before this one. The wall and keep bits are LogicHelpers' names, calls that return BOOLEnum, IsGateOrTowerArray and animationCycleNumberHasJustIncremented are tested by truthiness, the damage of a hit on a building and the state behind moveToFreeTileNearby are if / else (they were ternaries), the fade step is decremented without a pointer cast, and the casts that did nothing are gone (`(char)` on disappearFadeAlphaCountdown and the frame tables, `(short)` on BuildingLayer, `(int)` on widthOrHeight and on the fixedRng sum): none of these changes the object code. The `(short)` where mapTimeInTicks (uint) is stored into isSelectable_OR_matchTime (short) stays, as main's other units write that store. Kept, each with a comment and with what the other form reads: - `int building;` in the wall attack without a value: it is read behind the if / else, and with `= 0` (0.9799) or with the tile's building read in front of the test (0.9735) the match is lost. - `target > -1` where the stone is thrown: the original compares with the register that holds -1 (0x00573B4A); `>= 0` reads 0.9940. - The two arms on movementType_OR_targetUnitID that store the same pair: the original has the compare and one copy of the stores (0x005731BC); one arm reads 0.9951. The owner is read from the unit again where the original reads it again: as an argument of processDamageToBuildingThunk (0x005734FD) and into the wall attack's `attacker` (0x005735B2). Through the function's `owner` these read 0.9810 and 0.9269. compiler-flags-gl.txt gets UpdateSlinger.cpp only: hasUnitReachedDestination is on main's list already (quick_diff 0.4706 alone). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
One new entry, so that UpdateSlinger reads with OPENSHC_FUNCTION_VISIBILITY_UNITS on what it reads in the default build. It joins the group that holds hasUnitReachedDestination and names that callee, the one member it calls. Measured as sourcehold#491's pairs were (quick_diff, the unit's file with the callee's file pasted in front of it, against the unit alone): 0.4706 alone, 0.9955 with hasUnitReachedDestination. Each other /GL callee the unit calls was tried one at a time on top of it, without its own callees: none changes the ratio. What 0.9955 leaves are lines quick_diff writes two ways (0xffff and -1, 0xfffe and -2); the builds in the pull request read the unit 100.0%. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Style guide reading (advisory, posted once) 1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 1 reimplemented The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.
WhereRule 24 — Declare variables upon first use
|
…der-100 # Conflicts: # cmake/compiler-flags-gl.txt
gynt
approved these changes
Dec 2, 2026
gynt
enabled auto-merge
December 2, 2026 21:54
This was referenced Dec 3, 2026
gynt
approved these changes
Dec 4, 2026
gynt
disabled auto-merge
December 4, 2026 17:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Units::UpdateSlinger, from gynt's units branchreimpl/map-units-updatefunctions(his draft #204). It reads 100.0% in the default build and with main's function-visibility option on. The function's commit cites the commits of gynt's that measured the file and those that only touched its text.UpdateHealer and UpdateSpearman, which were worked on together with it, are in #545, the other PR of this round, which has no header change. Neither PR needs the other.
Units::UpdateSlinger"Before" is the status of gynt's last measured commit on the file; his later commits on it (6565c1b, 974c32f) were not measured.
Header change
UnitStategetsUS_UNKNOWN_123 = 123andEntityTypegetsET_UNKNOWN_35 = 35: one line in each header, in a commit of its own, named as the enums' other values without a known meaning are (US_UNKNOWN_120,US_UNKNOWN_121,ET_UNKNOWN_8,ET_UNKNOWN_30). Main has had both lines since its header sync d134c77, so once this PR is merged the commit adds nothing there.cmp eax, 0x7b), and the state it stores behindmoveToFreeTileNearbywhen that call left the unit in US_MOVE_TO_DESTINATION (0x005732D3:add ecx, 0x7b, which gives 123 there and 4, US_RELOAD_WEAPONUnk, otherwise).Unit::field_0x2c4holds the same state number. It is theshortright behindstateandcachedState, UpdateSlinger compares it with 123 in front of that call (0x0057329D), and the block the test guards is the one that stores state 123. So that test is written with the name too.push 0x23,shootProjectile's second argument).ET_SLINGERis 33.(UnitState)123and(EntityType)35and with the names, and so do the other PR's two files, which include both headers and use neither name (object files compared section by section, in the option-on layout and in the default one). The builds below are of the tree with the two lines.(UnitState)123for the same case label and the same store: UpdateArabianArcher, UpdateCrossbowman, UpdateCrusaderArcher and UpdateFireThrower. This PR leaves them as they are; they can take the name once main has it.Measured
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed: the data resolvers withtools/reimplementation-control/enable_reimplemented_data.py, the function resolvers of the.cppfiles in the build), and sourcehold's reccmp (a86aceb03) with--resolve-wrapped-calls --ignore-security-cookie. Normalised is main'sreccmp_report.pyfigure, which ignores call and tail-jump targets and resolver addresses./GLfile of that main; UpdateSlinger and six of main's units, UpdatePitchman, UpdateDairyFarmer, UpdateEngineer, UpdateFireBallista, UpdateCatapult and UpdateHopsFarmer, with their callee closures; every file of a function-visibility group that touches them), BUILD_OK and 0 failures in both modes. UpdateSlinger reads 100.0% / 100.0% (raw / normalised) in both, and so doeshasUnitReachedDestination. With the option on,cmake/function-visibility-units.pymakes 25 wrapper units, as on main; UpdateSlinger is in the one that holdshasUnitReachedDestination.UnitsStateand three files off the/GLlist. None of those files is among the 69 functions UpdateSlinger reaches through its calls, and no.cppcalls UpdateSlinger, so the builds were not repeated on the new main. The branch's own lines are the same on both, but for that(short).Buildings::UpdateCatapultBuildingreads 99.6% / 95.5% in both modes here; there it read 99.6% / 95.7% with the option off and 100.0% / 100.0% with it on.UnitsState::processEntityDamageToUnitreads 71.5% / 67.9% in both modes here; there it read the same with the option off and 77.3% / 69.0% with it on.Buildings::UpdateFireBallistaBuildingreads 99.6% / 95.5% with the option off (100.0% / 100.0% in main's build) and 100.0% / 100.0% with it on, as in main's. Its twinUpdateCatapultBuildingreads 99.6% / 95.5% in both modes (99.6% / 95.7% and 100.0% / 100.0% in main's). The two trade one early load with the build's file set, as they did in Reimplement six UnitsState functions at 100%, from gynt's text on main #539's builds.UnitsState::processEntityDamageToUnitreads 71.5% / 67.9% with the option off (77.3% / 69.0% in main's) and the same with it on, as in main's./GLfile of main is in the small builds, and only those files take part in link-time code generation. So the builds hold the new body and every function whose code it could shift: the other callers ofhasUnitReachedDestinationand of the other members of its group. The files outside/GLare compiled one at a time and can't see the new body, and no.cppnames the new function. The files outside the small builds that includeUnitState.hpporEntityType.hppwere not rebuilt with the two new lines; a new enumerator changes no existing value and no type's size.return;and an unusedusingremoved, one pair of parentheses, comments) was compiled both ways, the file with its callee pasted in front of it, in the option-on layout and in the default one, and the two object files were compared section by section: the same object code. A form that changed the object code was not taken; those are under "Kept as it is" with what they read. The small builds were made before the last of these edits, which put the(short)back on the tick store, so they are of the same object code.style_lint.py): nothing to fix automatically, no errors and 36 notes, all of the kinds under "Kept as it is" (the header change itself, 21 placeholder names, 4 casts, 4 declarations without a value and the bot's note on one of them, 3 hints forfield_0x58, one note on the mix of truth tests, one summary line).What got it to 100%
The text started from his draft and stood at 96.5% with the option on on our development branches; the commit lists what changed, with the original's addresses. The last step:
.x + widthOrHeight / 2and.y + widthOrHeight / 2. The original divides once and moves the quotient out ofeax(0x00573770), which leavesedxfree for the zero that the next test compares with and the state store uses (0x0057377F to 0x005737B6). With a local for the half size the quotient stays ineaxand that zero is an immediate.quick_diffwith the callee in the unit: 0.9814 -> 0.9955, where the lines left are the same bytes written two ways.The entry
hasUnitReachedDestinationand names that one callee, the one member of the group it calls. The commit gives what it reads alone (0.4706) and that no other/GLcallee changes the ratio.cmake/compiler-flags-gl.txt, as main's other units are; the callee it has to see is on that list already.Kept as it is
Each ratio is
quick_diffwith the callee in the unit; the text as it is reads 0.9955, which is a full match in the builds.int building;without a value (the wall attack), with a comment: it is read behind the if / else, and with= 0(0.9799) or with the tile's building read in front of the test (0.9735) the match is lost. This is the one line main's style-lint bot will note.int damage;beside it, as in main's UpdatePikeman: both arms behind it assign it.int targetX;/int targetY;: both arms of the test on the target assign them.target > -1where the stone is thrown, with a comment: the original compares with the register that holds -1 (0x00573B4A:cmp ebp, edx,jle);>= 0reads 0.9940. The state before it tests the same field with>= 0, as the original does there.movementType_OR_targetUnitID, with a comment: the original has the compare and one copy of the stores (0x005731BC); written as one arm they read 0.9951.ownerfrom its first lines (0x00572E91), and the original still reads it from the unit at two later places: an argument ofprocessDamageToBuildingThunk(0x005734FD) and the wall attack's localattacker(0x005735B2). Throughownerthey read 0.9810 and 0.9269.cmp cx, 0x1b0) sits in the else of the test for above 400 (0x00572FE9:cmp cx, 0x190), so its arm never runs. It is the original's code.(short)wheremapTimeInTicksis stored intoisSelectable_OR_matchTime: the tick count isuintand the field isshort, so the cast narrows. Main's other units write that store the same way (UpdateArabianArcher, UpdateCrossbowman, UpdateCrusaderArcher, UpdateFireThrower, UpdateLadderman).(char)onengineerManningSiegeStateRef_checkType, twice: the field isbytein the header, and the fade tests it for below 0 and for above 0, so it has to be read signed.(int)onmapTimeInTicksin the% 40, as in UpdatePikeman: the field isuint, and the original divides signed (0x005730B1:cdq,idiv).(char)ondisappearFadeAlphaCountdownand on the frame tables (bothcharin the headers),(short)onBuildingLayer[tile](short),(int)onwidthOrHeight(int) and on(fixedRng & 7) + 1(fixedRngisint).IsGateOrTowerArray,animationCycleNumberHasJustIncremented(both BOOLEnum) andisMatchingSpeed(abool) tested by truthiness;intcalls, the two-byte flags,field_0x3f8andDAT_UnitHasBecomeIdle(undefined4) compared with 0, as main does. That is the mix the checker notes.Unit::field_0x2c4: see "Header change".Unit::field_0x3f8, abytethat is only ever 0 or 1 here: cleared when the stone is thrown, tested and set to 1 where the slinger reports itself idle.Unit::field_0x430(ashort, set to 1 on every update),Unit::field_0x3bc(anint, set to -40 when the target is too far away to throw at),Unit::field_0x40e(abool, cleared at the frame the stone is thrown),Unit::field_0x2ac(ashort, set to 10 in one state).Unit::field_0x58is ashortthat takes 0 and 1; the checker's BOOLEnum hint for it comes from a field of the same name in another struct.field_0x824,field_0x2b80,field_0x2ba0,field_0x2c7c).Differences from the draft
We compared the operators and literals of every test against a number with gynt's draft. One test differs in what it tests, as the original has it:
closestEnemyMicroDistance <= 432(0x005730C6:cmp ..., 0x1b0; jg); the draft had< 432.The rest are the same tests written the other way round with their arms exchanged (
<= 70as> 70twice,<= 484as> 484,< 0as>= 0,> 0as<= 0),< 401as<= 400, BOOLEnum calls and fields tested by truthiness where the draft compares with 0, hex constants in decimal or as their enum names, and, in the sit-down state, one test for substate 101 where the draft nested it in a test for 101, 106 and 107. We did not read the file line by line against the draft.Other PRs
prepareProjectileTarget, which UpdateSlinger calls twice and sees in the default build: its body, and its return type tovoid. UpdateSlinger reads no result.quick_diffgives UpdateSlinger the same diff against the original with Reimplement UnitsState::prepareProjectileTarget at 100%, from gynt's text on main (one header line each in two files) #540's body and declaration as with main's, in both layouts (0.9955), so the order of the two doesn't matter. UpdateSlinger calls nothing else that Reimplement UpdateTanner, UpdateArmorer, UpdatePoleTurner, UpdateFletcher, UpdateBlacksmith and UpdateWoodcutter from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on #536 or Reimplement UnitsState::processMeleeInitiation with the original's code, from gynt's text on main #543 (ours, open) change.cmake/compiler-flags-gl.txt, where this one adds one, and two entries elsewhere incmake/function-visibility.txt. Reimplement UpdateTanner, UpdateArmorer, UpdatePoleTurner, UpdateFletcher, UpdateBlacksmith and UpdateWoodcutter from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on #536 (ours, open) adds lines at the same place and entries infunction-visibility.txttoo. Whichever of these merges later needs a small merge there: keep all the lines.cmake/function-visibility.txt. Other open PRs changecmake/compiler-flags-gl.txtas well: reimpl/BuildingsState #234, Reimpl/viewport render state #241, Reimpl/tile map state #242, Reimpl/GameStateStructures development #243, Reimpl/troop value state development #275, Reimplement 17 rendering, UI and GameSynchronyState functions (not yet 100%) #313, Reimplement 2 UI::MenuItems functions (draft, below 100%) #327, Reimplement 3 UI::MenuItems functions from gynt's drafts (not yet 100%) #328, Reimplement 67 Map::TileMapState functions (batch 2) #396, Reimplement 66 TroopValueState functions at 100% #501, Reimplement 59 TextManager and UserTextHandler functions at 100% #509, Landscape and wildlife: 17 functions, 10 at 100% #526, Entities, projectiles and fire: 17 functions, 3 at 100% #527, TroopValueState leftovers: 4 functions, 2 at 100% #528 and UI menu views and modals: 9 functions, none at 100% yet #529. No other open PR changesUnitState.hpporEntityType.hpp.findBestAttackTileByPathCost,resetTileAndClearMoat,TransformAndRenderPercentage), on 0cea04d and on a0dc309 alike. The builds above left them out, with their resolvers off. This PR doesn't touch them.🤖 Generated with Claude Code